home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Main.bin / SocketImpl.java < prev    next >
Text File  |  1998-09-22  |  7KB  |  223 lines

  1. /*
  2.  * @(#)SocketImpl.java    1.23 98/07/01
  3.  *
  4.  * Copyright 1995-1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  * 
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15. package java.net;
  16.  
  17. import java.io.IOException;
  18. import java.io.InputStream;
  19. import java.io.OutputStream;
  20. import java.io.FileDescriptor;
  21.  
  22. /**
  23.  * The abstract class <code>SocketImpl</code> is a common superclass 
  24.  * of all classes that actually implement sockets. It is used to 
  25.  * create both client and server sockets. 
  26.  * <p>
  27.  * A "plain" socket implements these methods exactly as 
  28.  * described, without attempting to go through a firewall or proxy. 
  29.  *
  30.  * @author  unascribed
  31.  * @version 1.23, 07/01/98
  32.  * @since   JDK1.0
  33.  */
  34. public abstract class SocketImpl implements SocketOptions {
  35.     /**
  36.      * The file descriptor object for this socket. 
  37.      *
  38.      * @since   JDK1.0
  39.      */
  40.     protected FileDescriptor fd;
  41.     
  42.     /**
  43.      * The IP address of the remote end of this socket. 
  44.      *
  45.      * @since   JDK1.0
  46.      */
  47.     protected InetAddress address;
  48.    
  49.     /**
  50.      * The port number on the remote host to which this socket is connected. 
  51.      *
  52.      * @since   JDK1.0
  53.      */
  54.     protected int port;
  55.  
  56.     /**
  57.      * The local port number to which this socket is connected. 
  58.      *
  59.      * @since   JDK1.0
  60.      */
  61.     protected int localport;   
  62.  
  63.     /**
  64.      * Creates either a stream or a datagram socket. 
  65.      *
  66.      * @param      stream   if <code>true</code>, create a stream socket;
  67.      *                      otherwise, create a datagram socket.
  68.      * @exception  IOException  if an I/O error occurs while creating the
  69.      *               socket.
  70.      * @since      JDK1.0
  71.      */
  72.     protected abstract void create(boolean stream) throws IOException;
  73.  
  74.     /**
  75.      * Connects this socket to the specified port on the named host. 
  76.      *
  77.      * @param      host   the name of the remote host.
  78.      * @param      port   the port number.
  79.      * @exception  IOException  if an I/O error occurs when connecting to the
  80.      *               remote host.
  81.      * @since      JDK1.0
  82.      */
  83.     protected abstract void connect(String host, int port) throws IOException;
  84.  
  85.     /**
  86.      * Connects this socket to the specified port number on the specified host.
  87.      *
  88.      * @param      address   the IP address of the remote host.
  89.      * @param      port      the port number.
  90.      * @exception  IOException  if an I/O error occurs when attempting a
  91.      *               connection.
  92.      * @since      JDK1.0
  93.      */
  94.     protected abstract void connect(InetAddress address, int port) throws IOException;
  95.  
  96.     /**
  97.      * Binds this socket to the specified port number on the specified host. 
  98.      *
  99.      * @param      host   the IP address of the remote host.
  100.      * @param      port   the port number.
  101.      * @exception  IOException  if an I/O error occurs when binding this socket.
  102.      * @since      JDK1.0
  103.      */
  104.     protected abstract void bind(InetAddress host, int port) throws IOException;
  105.  
  106.     /**
  107.      * Sets the maximum queue length for incoming connection indications 
  108.      * (a request to connect) to the <code>count</code> argument. If a 
  109.      * connection indication arrives when the queue is full, the 
  110.      * connection is refused. 
  111.      *
  112.      * @param      backlog   the maximum length of the queue.
  113.      * @exception  IOException  if an I/O error occurs when creating the queue.
  114.      * @since      JDK1.0
  115.      */
  116.     protected abstract void listen(int backlog) throws IOException;
  117.  
  118.     /**
  119.      * Accepts a connection. 
  120.      *
  121.      * @param      s   the accepted connection.
  122.      * @exception  IOException  if an I/O error occurs when accepting the
  123.      *               connection.
  124.      * @since   JDK1.0
  125.      */
  126.     protected abstract void accept(SocketImpl s) throws IOException;
  127.  
  128.     /**
  129.      * Returns an input stream for this socket.
  130.      *
  131.      * @return     a stream for reading from this socket.
  132.      * @exception  IOException  if an I/O error occurs when creating the
  133.      *               input stream.
  134.      * @since      JDK1.0
  135.     */
  136.     protected abstract InputStream getInputStream() throws IOException;
  137.  
  138.     /**
  139.      * Returns an output stream for this socket.
  140.      *
  141.      * @return     an output stream for writing to this socket.
  142.      * @exception  IOException  if an I/O error occurs when creating the
  143.      *               output stream.
  144.      * @since      JDK1.0
  145.      */
  146.     protected abstract OutputStream getOutputStream() throws IOException;
  147.  
  148.     /**
  149.      * Returns the number of bytes that can be read from this socket
  150.      * without blocking.
  151.      *
  152.      * @return     the number of bytes that can be read from this socket
  153.      *             without blocking.
  154.      * @exception  IOException  if an I/O error occurs when determining the
  155.      *               number of bytes available.
  156.      * @since      JDK1.0
  157.      */
  158.     protected abstract int available() throws IOException;
  159.  
  160.     /**
  161.      * Closes this socket. 
  162.      *
  163.      * @exception  IOException  if an I/O error occurs when closing this socket.
  164.      * @since      JDK1.0
  165.      */
  166.     protected abstract void close() throws IOException;
  167.  
  168.     /**
  169.      * Returns the value of this socket's <code>fd</code> field.
  170.      *
  171.      * @return  the value of this socket's <code>fd</code> field.
  172.      * @see     java.net.SocketImpl#fd
  173.      * @since   JDK1.0
  174.      */
  175.     protected FileDescriptor getFileDescriptor() {
  176.     return fd;
  177.     }
  178.  
  179.     /**
  180.      * Returns the value of this socket's <code>address</code> field.
  181.      *
  182.      * @return  the value of this socket's <code>address</code> field.
  183.      * @see     java.net.SocketImpl#address
  184.      * @since   JDK1.0
  185.      */
  186.     protected InetAddress getInetAddress() {
  187.     return address;
  188.     }
  189.  
  190.     /**
  191.      * Returns the value of this socket's <code>port</code> field.
  192.      *
  193.      * @return  the value of this socket's <code>port</code> field.
  194.      * @see     java.net.SocketImpl#port
  195.      * @since   JDK1.0
  196.      */
  197.     protected int getPort() {
  198.     return port;
  199.     }
  200.  
  201.     /**
  202.      * Returns the value of this socket's <code>localport</code> field.
  203.      *
  204.      * @return  the value of this socket's <code>localport</code> field.
  205.      * @see     java.net.SocketImpl#localport
  206.      * @since   JDK1.0
  207.      */
  208.     protected int getLocalPort() {
  209.     return localport;
  210.     }
  211.     
  212.     /**
  213.      * Returns the address and port of this socket as a <code>String</code>.
  214.      *
  215.      * @return  a string representation of this socket.
  216.      * @since   JDK1.0
  217.      */
  218.     public String toString() {
  219.     return "Socket[addr=" + getInetAddress() +
  220.         ",port=" + getPort() + ",localport=" + getLocalPort()  + "]";
  221.     }
  222. }
  223.